package service;

import java.util.ArrayList;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ccc.dao.AdDao;
import com.ccc.model.Ad;
import com.ccc.model.Product;
import com.ccc.model.User;
import com.ccc.service.AdService;
import com.ccc.service.ProductService;

public class AdServiceTestTest {
	
	public static AdService adService;
	public static ProductService  productService;
	public static AdDao adDao;
	
	@BeforeClass
	public static void beforeClass(){
		ApplicationContext ac = new  ClassPathXmlApplicationContext("beans.xml");
		adService = (AdService)ac.getBean("adService");
		productService = (ProductService) ac.getBean("productService");
		adDao = (AdDao)ac.getBean("adDao");
	}

	@Test
	public void testFindAds(){
		int currenttime = 1;
		User user = new User();
		user.setUserId(1);
		user.setUserName("ch");
		user.setUserPass("ch");
		List<Ad> l = adDao.findAds(user, currenttime);
		System.out.println(l);
		System.out.println(l==null);
		System.out.println(l.size());
	}
	
	@Test
	public void testAddAds() {
		int currenttime = 1;
		User user = new User();
		user.setUserId(1);
		user.setUserName("ch");
		user.setUserPass("ch");
		Product product = productService.getById(9);
		List<Ad> ads = new ArrayList<Ad>();
		Ad ad = new Ad();
		ad.setCurrentTime(currenttime);
		ad.setUser(user);
		for(int i = 0; i< 3;i++){
			product.setProductVol(i+1);
			product.setRdCost(100*(i+1));
			product.setRdCycle(2+i);
			product.setStockCost(i+1);
			ad.setAdPrice(10000+5000*i);
			ad.setProduct(product);
			ads.add(ad);
		}
		boolean flag = adService.addAds(ads, user, currenttime);
		org.junit.Assert.assertFalse(flag);
		System.out.println(flag);
	}

}
